/**
 * IM 接口说明：
 * 
 * 1.当前用户ID，IM服务器会尝试从Cookie获取UID，如果不能取到，会尝试从请求参数uid获取。
 * 2.服务器提供的不同命令包括：
 * 		a. msg （地址 /msg）用于一个用户向另一个用户发送消息。
 * 			需要的参数有：tuid 消息发给那个用户
 * 						 msg：消息的内容
 * 						 uid：用户id，可选
 * 			
 * 		b. cmd （地址 /cmd）用于发送用户自己的控制消息，比如打开了聊天窗口，控制所有会话中界面一致。
 * 			需要的参数：
 * 					 target：消息的内容
 * 					 uid：用户id，可选
 * 					
 * 					 type:命令的类型
 *			   				Default,//0聊天消息
 *							StatusChange,//1状态改变
 *							ChatTo,//2打开于对应用户的聊天窗口
 *							MinChatWin, //3最小化聊天窗口
 *							MaxChatWin,//4最大化聊天窗口
 *							CloseChatWin,//5关闭聊天窗口
 *							
 *							MinListWin,//6最小化列表窗口
 *							MaxListWin,//7最大化列表窗口
 *							HeartBeat//8最大化列表窗口
 * 		c. pull（地址 /pull）用户从服务器端拖即使消息。如果拖不到会一直等着。
 *  		需要的参数：
 *  			key：客户端生成的随机整数，代表一个唯一的会话。一个用户可以维护多个会话
 *  			from：下一条消息的id，避免漏包
 *  			uid：用户id，可选
 *  
 *  		pull返回的结果：
 *  			from: 消息来源的用户id
 *  			type：	消息类型
 *  					0：为普通对话消息
 *  					1：控制消息，如果是控制消息，content为对象
 *  			id：消息的序列号，在一次回话中，从1开始一直递增
 *    			content：消息的内容
 *    				type=0时，为普通字符串
 *    				type=1时，为对象，包括以下字段
 *    					好友状态改变： 
 *    							{type:'status',status:1}
 *    					打开于对应用户的聊天窗口
 *    							{ fun:'IM.chatTo(123,true)'} 
 *    							//使用key过滤掉自己的消息，fun用于执行的函数
 *    
 *    					
 *  
 *  	d.list （地址 /list）从服务器获取好友列表
 *  		需要的参数：
 *  		返回的结果需要包括：
 *  				
 *  
 * 
 */ 
var IM = {
	
 
	fromIndex : 0,
	userId : 1,
	urlbase:"http://im.dianziq.com",
	key : parseInt(Math.random() * 10000000),
	friends : [],
	onlineCount : 0,
	pull : function() {
		$.ajax({
		    method:"get",
		    url:IM.urlbase+"/pull",
		    scriptCharset: "utf-8" ,
		    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
		    data:{uid:this.userId,from:this.fromIndex,key:this.key},
		    dataType :"jsonp",
		    jsonpCallback:"IM.onMsg"
		})
		 .done(function() { 
			 IM.pull();
		 })
		 .fail(function() { 
			 IM.pull();

			 
		 
		 })
	},
	onMsg:function(msg){
		
		if(msg.type==1){
			//
			var o=msg.content;
			if(o.key==this.key){ //自己发出的消息
				return;
			}
			if(o.fun){
				eval(o.fun);
				return;
			}
			 
			return;
		}
		if(msg.from==this.userId){//my msg
			var s='<dd class="wbim_msgr"><div class="wbim_msgpos"><div class="msg_time">'+new   Date().toLocaleString();
			s+='</div><div class="msg_box"><p class="txt">'+msg.content+'</p></div><div class="msg_arr"></div></div></dd>';
			var ele=this.getChatListById(msg.to);
			ele.append(s);
			ele.parent().scrollTop(10000);
			
		}else if(msg.to==this.userId){
			var s='<dd class="wbim_msgl"><div class="wbim_msgpos"><div class="msg_time">'+new   Date().toLocaleString();
			s+='</div><div class="msg_box"><p class="txt">'+msg.content+'</p></div><div class="msg_arr"></div></div></dd>';
		
			var ele=this.getChatListById(msg.from);
			ele.append(s);
			ele.parent().scrollTop(10000);
		}
	},
	sendJsonp:function(url,o){
		$.ajax({
		    method:"get",
		    url:IM.urlbase+url,
		    scriptCharset: "utf-8" ,
		    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
		    data:o,
		    dataType :"jsonp"
		});
	},
	sendMsg : function(msg) {
		var touid=this.getActiveTab().attr("uid");
		if(!touid){
			alert("Cannot find user");
			return ;
		}
		var a={};
		a.uid=this.userId;
		a.tuid=touid;
		a.msg=msg;
		this.sendJsonp("/msg",a);
	

	 
	},
	sendCmd:function(obj){
		var a={};
		a.uid=this.userId;
		a.msg=obj;
		 
		this.sendJsonp("/cmd",a);
	},
	

	renderList : function() {
		this.onlineCount = 0;
		this.getListUL().empty();
		this.friends.sort(function(v1,v2){
			if(v1.status==v2.status){
				return v1.name-v2.name;
			}
			return v1.status-v2.status;
		});
		for ( var i = 0; i < this.friends.length; i++) {
			var f = this.friends[i];
			var a="offline";
			if (f.status == 0) {
				this.onlineCount++;
				a="online";
			}
			  
			var li = '<li  class="wbim_'+a+'" onclick="IM.chatTo(' + f.id + ')" title="' + f.name
					+ '" uid="' + f.id + '" >';
			li += '<div class="wbim_userhead"  >';
			li += '<img src="http://img.dianziq.com/wendaimg/l_' + f.img + '">';
			li += '<span style="DISPLAY: none" class="wbim_icon_msg_s"></span><span class="wbim_status_'+a+'"></span></div>';
			li += '<div class="wbim_username">' + f.name + '</div>';
			li += '</li>';
			this.getListUL().append(li);
		}
	},
	// 获取好友列表
	fetchList : function() {
		$.ajax({
		    method:"get",
		    url:IM.urlbase+"/list",
		    scriptCharset: "utf-8" ,
		    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
		    data:{uid:this.userId },
		    dataType :"jsonp",
		    jsonpCallback:"IM.onList"
		})
		 
	 .fail(function() {  	 })

	},
	onList:function(f){
		this.friends = f;
		this.renderList();
	},
	//在线状态改变
	OSC:function(uid,status){
		var f=this.getFriend(uid);
		if(f ){
			f.status=status;
		}
		this.renderList();
	},
	// 获取好友信息
	getFriend : function(uid) {
		for ( var i = 0; i < this.friends.length; i++) {
			if (this.friends[i].id == uid) {
				return this.friends[i];
			}
		}
		return null;
	},
	getListUL : function() {
		return $(".wbim_list_group ul");

	},
	
	getActiveTab:function(){
		return $("ul.wbim_chat_friend_list .wbim_active");
	},
	getFirstTab:function(){
		return $("ul.wbim_chat_friend_list li:first-child");
	},
	
	getTabById:function(id){
		return $("ul.wbim_chat_friend_list li[uid=\""+id+"\"]");
	},
	getChatListById:function(id){
		var u= $(".wbim_chat_list dl[uid="+id+"]");
		if(u.length>0){
			return u;
		}
		 
		else{
			this.chatConentList.append('<dl  uid="'+id+'"></dl>')
		}
		return $(".wbim_chat_list dl[uid="+id+"]");
	},
	activeTab:function(id,nottrigger){
		var a=this.getActiveTab();
		if(a){
			a.removeClass("wbim_active");
		}
		var at=this.getTabById(id);
		if(at){
			at.addClass("wbim_active");
		}
		 
		this.onActiveTabChange(nottrigger);
		 
	},
		
	getStatusCssName:function(uid){
		var stat=["wbim_status_online","wbim_status_busy","wbim_status_away","wbim_status_offline"]

		var s=this.getFriend(uid).status;
		return stat[s];
	}
	,
	onActiveTabChange:function(nottrigger){
		var a=this.getActiveTab();
		if(a.length==0){
			alert("error!");
			return;
		}
		var uid=a.attr("uid");
		$(".wbim_chat_list dl").hide();
		this.getChatListById(uid).show();  
		if(uid){
			var name=a.attr("title");
			$(".wbim_min_nick ").text(name);
			$(".wbim_tit_lf p span:first-child").css(this.getStatusCssName(uid));
			$(".wbim_tit_lf p span a").text(name);
			
			
			
			
		}
		if(nottrigger)return;
		
		this.sendCmd( '{ fun:"IM.chatTo('+uid+',true)"} ');
	},
	/**
	 * nottrigger  不触发级联动作
	 */
	chatTo : function(uid,nottrigger) {
		$(".wbim_chat_box").fadeIn();
		var f = this.getFriend(uid);
		if (f == null) {
			alert("Cannot find :" + uid);
			return;

		}
		
	 
		if(this.getTabById(uid).length>0){
			this.activeTab(uid,nottrigger);
			return;
		}
		 this.getActiveTab().removeClass("wbim_active");
	 	 
		 

		var li = '<li onclick="IM.chatTo('+f.id+')" title="' + f.name + '" uid=' + f.id
				+ ' class=" wbim_active"><div class="wbim_userhead">';
		li += '<img src="http://img.dianziq.com/wendaimg/l_' + f.img + '">';
		li += '<span   class="wbim_status_online"></span>';
		li += '</div><div class="wbim_username"  >' + f.name + '</div>';
		li += '<a hidefocus="true"   class="wbim_icon_close_s" node-type="wbim_icon_close_s"></a></li>';
		this.chatList.append(li);
		 $(".wbim_active a.wbim_icon_close_s").click(function(event){
			 event.stopPropagation();
			 IM.closeChat(f.id);
		 });
		 
		 this.onActiveTabChange(nottrigger);
		
	},
	
	closeChat : function( id) {
		this.getTabById(id).remove();
		if(this.getActiveTab().length==0){
			var first=this.getFirstTab();
			if(first.length>0){
				
				first.addClass("wbim_active");
				this.onActiveTabChange();
			}
			else{
				this.closeChatWindow();
			}
		}
		 
	},

	closeChatWindow:function(nottrigger){
		$(".wbim_chat_box").fadeOut();
		IM.minBox.attr("class", "wbim_min_box_col2");
		//$(".wbim_chat_box * a.wbim_icon_close").trigger("click");
		if(nottrigger)
			return;
		this.sendCmd( '{ fun:"IM.closeChatWindow( true)"} ');
	},
	minChatWindow:function(nottrigger){
		$(".wbim_chat_box").fadeOut();
	 
		this.minBox.attr("class", "wbim_min_box_col3");
		if(nottrigger)
			return;
		this.sendCmd( '{ fun:"IM.minChatWindow( true)"} ');
	},
	maxChatWinow:function(nottrigger){
		$(".wbim_chat_box").fadeIn();
		if(nottrigger)
			return;
		this.sendCmd( '{ fun:"IM.maxChatWinow( true)"} ');
	},
	maxListWinow:function(nottrigger){
		$(".wbim_list_expand").slideDown();
		if(nottrigger)
			return;
		this.sendCmd( '{ fun:"IM.maxListWinow( true)"} ');
	},
	minListWinow:function(nottrigger){
		$(".wbim_list_expand").slideUp();
		if(nottrigger)
			return;
		this.sendCmd( '{ fun:"IM.minListWinow( true)"} ');
	},
	 
 

	regEvents : function() {
		this.minBox = $(".wbim_min_box_col2");
		this.chatList = $("ul.wbim_chat_friend_list");
		this.chatConentList=$(".wbim_chat_list");

		// 提示条
		$(".wbim_chat_tips .wbim_icon_close_s").click(function() {
			$(".wbim_chat_tips").fadeOut();
		});
		// 关闭聊天窗口
		$(".wbim_chat_box * .wbim_tit_rt a.wbim_icon_close").click(function() {
			IM.closeChatWindow();
		});
		// 最小化聊天窗口
		$(".wbim_chat_box * a.wbim_icon_mini").click(function() {
			IM.minChatWindow();
		});
		// 最大化聊天窗口
		$(".wbim_min_chat").click(function() {
			
			IM.maxChatWinow();
		});

		// 最小化列表窗口
		$(".wbim_list_expand * .wbim_icon_mini").click(function() {
			IM.minListWinow();
		});
		$(".wbim_clicknone").click(function() {
			IM.minListWinow();
		});

		// 最大化列表窗口
		$(".wbim_min_friend").click(function() {
			IM.maxListWinow();
		});
		//发送按钮
		$(".wbim_btn_publish").click(function(){
			var e=$(".wbim_chat_input textarea");
			IM.sendMsg(e.val());
			e.val("");
			
			
		});
		//打开表情
		$(".wbim_tool_ctrl").click(function(){
			$(".wbim_face_box").show();
		});
		//关闭表情
		$(".wbim_face_tit .wbim_icon_close").click(function(){
			$(".wbim_face_box").hide();
		});
		$(".wbim_face_list li a img").click(function(event){
			var e=$(".wbim_chat_input textarea"); 
			e.val(e.val()+$(event.target).parent().attr("title"));
			$(".wbim_face_box").hide();
		});
		
	},
	init : function(uid) {
		this.userId=parseInt(uid);
		if(this.userId&&this.userId>0){
 			var a='<div style="POSITION: fixed; BOTTOM: 0px; RIGHT: 20px" id="wbim_box"  class="wbim_box">  <div  style="Z-INDEX: 1001; POSITION: absolute; WIDTH: 1px; BOTTOM: 2px; HEIGHT: 1px; RIGHT: 2px"  id="webim_swf_box"></div>  <div  style="Z-INDEX: 1500; POSITION: absolute; WIDTH: 95px; BOTTOM: 119px; HEIGHT: 18px; OVERFLOW: hidden; RIGHT: 360px">  </div>  <div style="Z-INDEX: 1001; BOTTOM: 0px; display: none; RIGHT: 0px"  class="wbim_list_expand">  <div class="wbim_list_con">  <div class="wbim_tit">  <div class="wbim_titin">  <div class="wbim_tit_lf">  <div node-type="status_manager" sizcache="2">  <div class="tit" sizcache="2">  <span class="wbim_status_offline"></span><span class="txt">隐身</span><span  class="icon"></span>  </div>  <div class="linert"></div>  <ul style="DISPLAY: none">  <li class="lingtop"></li>  <li sizcache="2"><a href="javascript:void(0)"  sizcache="2"><span class="wbim_status_online"></span>在线</a></li>  <li><a href="javascript:void(0)"><span  class="wbim_status_busy"></span>忙碌</a></li>  <li><a href="javascript:void(0)"><span  class="wbim_status_away"></span>离开</a></li>  <li><a href="javascript:void(0)"><span  class="wbim_status_offline"></span>隐身</a></li>  </ul>  </div>  </div>  <div class="wbim_tit_rt">  <a class="wbim_icon_setup" title="设置"  href="http://weibo.com/settings/notice#webim" target="_blank"  suda-uatrack="key=tblog_webim_behavior&amp;value=click_install_button"></a><a  hidefocus="" class="wbim_icon_mini" title="最小化"  href="javascript:;"  suda-uatrack="key=tblog_webim_behavior&amp;value=click_mini_button"></a>  </div>  </div>  </div>  <div class="wbim_line"></div>  <div class="wbim_list_up">  <div class="wbim_list_srch">  <div class="wbim_list_srchin">  <a hidefocus="" style="DISPLAY: none" class="wbim_icon_close_s"  href="javascript:void(0)"  suda-uatrack="key=tblog_webim_behavior&amp;value=click_empty_button"></a><input  value="查找好友" type="text">  </div>  </div>  </div>  <div  style="Z-INDEX: 1; POSITION: absolute; BACKGROUND-COLOR: white; WIDTH: 180px; DISPLAY: none; HEIGHT: 31px; OVERFLOW: hidden; TOP: 74px; LEFT: 2px"  class="wbim_float_group_tit"></div>  <div class="wbim_list_box">  <div class="wbim_list_friend">  <div class="wbim_list_group">  <div class="wbim_list_group_tit wbim_open" title="我的好友"  action-type="UserGroup.Onclick"  action-data="id=normalusernogroup">  我的好友 [ <span title="在线好友">1</span> ]  </div>  <ul>  </ul>  </div>  </div>  <div style="DISPLAY: none" class="wbim_list_friend"></div>  <div class="wbim_list_friend">  <ul></ul>  </div>  </div>  <div class="wbim_list_pos">  <a hidefocus="" class="wbim_clicknone" href="javascript:;"  suda-uatrack="key=tblog_webim_behavior&amp;value=click_bottom_button"><span  class="wbim_icon_arrd"></span></a>  </div>  </div>  </div>  <div  style="Z-INDEX: 1001; POSITION: absolute; BOTTOM: 0px; DISPLAY: none; RIGHT: 199px"  class="wbim_chat_box" node-type="wbim_chat_box">  <div class="wbim_chat_con" node-type="wbim_chat_con">  <div class="wbim_tit" node-type="wbim_tit">  <div class="wbim_titin" node-type="wbim_titin">  <div class="wbim_tit_lf">  <p node-type="wbim_single_user">  <span class="wbim_status_offline" node-type="wbim_status"></span><span  class="txt"><a title="自由kirayuan"  href=" http://weibo.com/bluekeyv?source=webim" target="_blank"  suda-uatrack="key=tblog_webim_behavior&amp;value=click_nickname">自由kirayuan</a></span><span  style="DISPLAY: none" class="bringin"  node-type="wbim_tit_lf_count">正在输入</span>  </p>  <p style="DISPLAY: none" node-type="wbim_group">  <span class="wbim_icon_group_tit"></span><span class="txt"><a  target="_blank" node-type="wbim_tit_lf_gname"></a><em  class="txtg">在线成员(<a title="查看在线成员" target="_blank"  node-type="group_num"  suda-uatrack="key=tblog_webim_behavior&amp;value=click_online_friends"></a>)  </em></span>  </p>  </div>  <div class="wbim_tit_rt">  <a hidefocus="" class="wbim_icon_mini" title="最小化"  href="javascript:;" node-type="wbim_icon_mini"></a><a  hidefocus="" class="wbim_icon_close" title="关闭"  href="javascript:;" node-type="wbim_icon_close"></a>  </div>  </div>  </div>  <div  style="Z-INDEX: 1002; POSITION: absolute; DISPLAY: none; TOP: 24px; RIGHT: 316px">  <div style="WIDTH: 316px; HEIGHT: 365px" class="wbim_box_pop"></div>  <div style="TOP: 145px; LEFT: 50px" class="wbim_confirm_box">  <div class="wbim_confirm_info">  <p class="wbim_confirm_p">  <span class="wbim_icon_tips"></span><span class="txt"  node-type="txt"></span>  </p>  <p class="wbim_confirm_btn">  <a hidefocus="" class="wbim_btn_c" href="javascript:;"><em>确定</em></a>  </p>  </div>  </div>  </div>  <div style="VISIBILITY: visible" class="wbim_chat_lf"  node-type="wbim_chat_lf">  <a hidefocus="" class="wbim_scrolltop_n" onclick="return false;"  href="javascript:;" node-type="wbim_scrolltop"></a>  <div class="wbim_chat_friend_box">  <ul class="wbim_chat_friend_list"  node-type="wbim_chat_friend_list">  </ul>  </div>  <a hidefocus="" class="wbim_scrollbtm_n" onclick="return false;"  href="javascript:;" node-type="wbim_scrollbtm"></a>  </div>  <div class="wbim_chat_rt">  <div class="wbim_chat_up">  <div style="DISPLAY: block" class="wbim_chat_tips"  node-type="wbim_chat_tips">  <span class="wbim_icon_tips"></span><span  node-type="wbim_chat_tips_content">对方当前不在线或隐身，可能无法立即回复。</span><a  hidefocus="" class="wbim_icon_close_s" href="javascript:;"  node-type="wbim_icon_close_s"></a>  </div>  <div style="HEIGHT: 198px; TOP: 24px" class="wbim_chat_list">  <dl style="DISPLAY: none" uid="2170252520">  <dd class="wbim_msgr">  <div class="wbim_msgpos">  <div class="msg_time">9-7 13:52</div>  <div class="msg_box">  <p class="txt">我本来以为发不出去</p>  </div>  <div class="msg_arr"></div>  </div>  </dd>  <dd class="wbim_msgr">  <div class="wbim_msgpos">  <div class="msg_time">9-7 13:53</div>  <div class="msg_box">  <p class="txt">不好意思啊，打扰你休息了</p>  </div>  <div class="msg_arr"></div>  </div>  </dd>  <dd class="wbim_msgl">  <div class="wbim_msgpos">  <div class="msg_time">9-7 13:53</div>  <div class="msg_box">  <p class="txt">呵呵</p>  </div>  <div class="msg_arr"></div>  </div>  </dd>  <dd class="line"></dd>  </dl>  <dl style="DISPLAY: none" uid="1163688452"></dl>  <dl style="DISPLAY: none" uid="2052503527"></dl>  <dl style="DISPLAY: none" uid="1564005361"></dl>  <dl style="DISPLAY: none" uid="1097403392"></dl>  <dl style="DISPLAY: block" uid="1176209312"></dl>  </div>  </div>  <div class="wbim_chat_toolbar" node-type="wbim_chat_toolbar">  <div class="wbim_chat_toolbarin" node-type="wbim_chat_toolbarin">  <div class="wbim_face" node-type="wbim_face">  <a hidefocus="" class="wbim_tool_ctrl" title="普通表情"  href="javascript:;" node-type="wbim_icon_face"><i  class="wbim_icon_face"></i>表情</a>  <div style="DISPLAY: none" class="wbim_face_box"  node-type="wbim_face_box">  <div class="wbim_face_tit">  <div class="wbim_face_arr"></div>  <div class="wbim_face_tit_lf">普通表情</div>  <a class="wbim_icon_close" href="javascript:;"  node-type="wbim_icon_close"></a>  </div>  <div class="wbim_face_con">  <ul class="wbim_face_list" node-type="wbim_face_list">  <li><a title="[织]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/41/zz2_org.gif"></a></li>  <li><a title="[神马]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/60/horse2_org.gif"></a></li>  <li><a title="[浮云]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/bc/fuyun_org.gif"></a></li>  <li><a title="[给力]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/c9/geili_org.gif"></a></li>  <li><a title="[围观]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/f2/wg_org.gif"></a></li>  <li><a title="[威武]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/70/vw_org.gif"></a></li>  <li><a title="[熊猫]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/6e/panda_org.gif"></a></li>  <li><a title="[兔子]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/81/rabbit_org.gif"></a></li>  <li><a title="[奥特曼]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/bc/otm_org.gif"></a></li>  <li><a title="[囧]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/15/j_org.gif"></a></li>  <li><a title="[互粉]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/89/hufen_org.gif"></a></li>  <li><a title="[礼物]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/c4/liwu_org.gif"></a></li>  <li><a title="[呵呵]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/ac/smilea_org.gif"></a></li>  <li><a title="[嘻嘻]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/0b/tootha_org.gif"></a></li>  <li><a title="[哈哈]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/6a/laugh.gif"></a></li>  <li><a title="[可爱]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/14/tza_org.gif"></a></li>  <li><a title="[可怜]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/af/kl_org.gif"></a></li>  <li><a title="[挖鼻屎]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/a0/kbsa_org.gif"></a></li>  <li><a title="[吃惊]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/f4/cj_org.gif"></a></li>  <li><a title="[害羞]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/6e/shamea_org.gif"></a></li>  <li><a title="[挤眼]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/c3/zy_org.gif"></a></li>  <li><a title="[闭嘴]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/29/bz_org.gif"></a></li>  <li><a title="[鄙视]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/71/bs2_org.gif"></a></li>  <li><a title="[爱你]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/6d/lovea_org.gif"></a></li>  <li><a title="[泪]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/9d/sada_org.gif"></a></li>  <li><a title="[偷笑]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/19/heia_org.gif"></a></li>  <li><a title="[亲亲]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/8f/qq_org.gif"></a></li>  <li><a title="[生病]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/b6/sb_org.gif"></a></li>  <li><a title="[太开心]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/58/mb_org.gif"></a></li>  <li><a title="[懒得理你]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/17/ldln_org.gif"></a></li>  <li><a title="[右哼哼]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/98/yhh_org.gif"></a></li>  <li><a title="[左哼哼]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/6d/zhh_org.gif"></a></li>  <li><a title="[嘘]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/a6/x_org.gif"></a></li>  <li><a title="[衰]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/af/cry.gif"></a></li>  <li><a title="[委屈]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/73/wq_org.gif"></a></li>  <li><a title="[吐]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/9e/t_org.gif"></a></li>  <li><a title="[打哈气]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/f3/k_org.gif"></a></li>  <li><a title="[抱抱]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/27/bba_org.gif"></a></li>  <li><a title="[怒]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/7c/angrya_org.gif"></a></li>  <li><a title="[疑问]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/5c/yw_org.gif"></a></li>  <li><a title="[馋嘴]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/a5/cza_org.gif"></a></li>  <li><a title="[拜拜]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/70/88_org.gif"></a></li>  <li><a title="[思考]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/e9/sk_org.gif"></a></li>  <li><a title="[汗]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/24/sweata_org.gif"></a></li>  <li><a title="[困]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/7f/sleepya_org.gif"></a></li>  <li><a title="[睡觉]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/6b/sleepa_org.gif"></a></li>  <li><a title="[钱]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/90/money_org.gif"></a></li>  <li><a title="[失望]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/0c/sw_org.gif"></a></li>  <li><a title="[酷]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/40/cool_org.gif"></a></li>  <li><a title="[花心]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/8c/hsa_org.gif"></a></li>  <li><a title="[哼]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/49/hatea_org.gif"></a></li>  <li><a title="[鼓掌]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/36/gza_org.gif"></a></li>  <li><a title="[晕]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/d9/dizzya_org.gif"></a></li>  <li><a title="[悲伤]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/1a/bs_org.gif"></a></li>  <li><a title="[抓狂]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/62/crazya_org.gif"></a></li>  <li><a title="[黑线]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/91/h_org.gif"></a></li>  <li><a title="[阴险]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/6d/yx_org.gif"></a></li>  <li><a title="[怒骂]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/89/nm_org.gif"></a></li>  <li><a title="[心]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/40/hearta_org.gif"></a></li>  <li><a title="[伤心]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/ea/unheart.gif"></a></li>  <li><a title="[猪头]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/58/pig.gif"></a></li>  <li><a title="[ok]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/d6/ok_org.gif"></a></li>  <li><a title="[耶]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/d9/ye_org.gif"></a></li>  <li><a title="[good]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/d8/good_org.gif"></a></li>  <li><a title="[不要]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/c7/no_org.gif"></a></li>  <li><a title="[赞]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/d0/z2_org.gif"></a></li>  <li><a title="[来]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/40/come_org.gif"></a></li>  <li><a title="[弱]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/d8/sad_org.gif"></a></li>  <li><a title="[蜡烛]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/91/lazu_org.gif"></a></li>  <li><a title="[钟]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/d3/clock_org.gif"></a></li>  <li><a title="[蛋糕]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/6a/cake.gif"></a></li>  <li><a title="[话筒]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/1b/m_org.gif"></a></li>  <li><a title="[圣诞老人]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/c5/chrisfather_org.gif"></a></li>  <li><a title="[圣诞铃铛]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/64/chrisbell_org.gif"></a></li>  <li><a title="[圣诞袜]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/08/chrisocks_org.gif"></a></li>  <li><a title="[圣诞树]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/a2/christree_org.gif"></a></li>  <li><a title="[圣诞帽]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/06/chrishat_org.gif"></a></li>  <li><a title="[雪人]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/d9/xx2_org.gif"></a></li>  <li><a title="[雪]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/00/snow_org.gif"></a></li>  <li><a title="[温暖帽子]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/f1/wennuanmaozi_org.gif"></a></li>  <li><a title="[手套]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/72/shoutao_org.gif"></a></li>  <li><a title="[围脖]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/3f/weijin_org.gif"></a></li>  <li><a title="[照相机]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/33/camera_org.gif"></a></li>  <li><a title="[茶]" href="javascript:;"><img  src="http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/a8/cha_org.gif"></a></li>  </ul>  <div class="tsina_loading cter">  <span class="tsina_ico_ldg"></span>  </div>  </div>  </div>  </div>  <div class="wbim_face" title="上传图片">  <a hidefocus="" class="wbim_tool_ctrl" href="javascript:;"><i  class="wbim_icon_img"></i>图片</a>  </div>  <div class="wbim_face" title="上传文件">  <a hidefocus="" class="wbim_tool_ctrl" href="javascript:;"><i  class="wbim_icon_doc"></i>文件</a>  </div>  <a hidefocus="" style="DISPLAY: none; MARGIN-LEFT: 10px"  class="wbim_icon_group" href="javascript:;"></a><a  class="wbim_history" title="私信记录"  href="http://weibo.com/message/talklist.php?source=webim&amp;uid=1176209312"  target="_blank" node-type="wbim_history_user"  suda-uatrack="key=tblog_webim_behavior&amp;value=click_chats_button"><span  class="wbim_icon_chatdoc"></span>私信记录</a><a style="DISPLAY: none"  class="wbim_history" title="聊天记录" target="_blank"  node-type="wbim_history_group"  suda-uatrack="key=tblog_webim_behavior&amp;value=click_chats_button"><span  class="wbim_icon_chatdoc"></span>聊天记录</a>  </div>  </div>  <div style="MARGIN-TOP: 1px" class="wbim_chat_input"  node-type="wbim_chat_input">  <div style="DISPLAY: none" class="wbim_chat_input_tips"  node-type="root">  <div style="DISPLAY: none" class="wbim_tips_pos_n"  node-type="wbim_tips_pic">  <div class="wbim_tips_pic_n">  <a href="javascript:;"><img style="CURSOR: pointer" alt=""  node-type="img_preview" action-type="wbim_img_preview"></a>  </div>  <span class="wbim_p_arr"></span>  </div>  <div class="fl"></div>  <div class="fr"></div>  </div>  <textarea node-type="wbim_chat_input_ta"></textarea>  </div>  <div class="wbim_chat_btm">  <div class="wbim_chat_btmin">  <div class="wbim_chat_btm_rt">  <p class="wbim_tips_char">  <span>185</span><span class="spetxt" node-type="spetxt"></span>  </p>  <div class="wbim_btn_send" node-type="wbim_btn_send">  <a hidefocus="" class="wbim_btn_publish" title="发送"  href="javascript:;">发送</a>  <div class="wbim_btn_choose">  <a class="wbim_btn_choose_a" node-type="wbim_btn_choose_a">选择</a>  <ul>  <li class="curr" node-type="wbim_enter_send_li"><span></span><em><a  href="javascript:;" node-type="wbim_enter_send">按Enter键发送</a></em></li>  <li class="line"><span></span><em></em></li>  <li><span></span><em><a href="javascript:;">按Ctrl+Enter键发送</a></em></li>  </ul>  </div>  </div>  </div>  </div>  </div>  </div>  </div>  <div  style="Z-INDEX: 100; POSITION: absolute; DISPLAY: none; TOP: 150px; LEFT: 130px"  node-type="wbim_confirm_box">  <div class="wbim_confirm_box">  <div class="wbim_confirm_con">  <div class="wbim_confirm_info">  <p class="wbim_confirm_p">  <span class="wbim_icon_ask"></span><span class="txt">提示：关闭会话窗口后，其中的未读私信将不再重复提醒。</span>  </p>  <p class="wbim_confirm_btn">  <a class="wbim_btn_c" href="javascript:;"><em>确认</em></a><a  class="wbim_btn_n" href="javascript:;"><em>取消</em></a>  </p>  </div>  </div>  </div>  <div  style="POSITION: absolute; WIDTH: 420px; HEIGHT: 365px; TOP: -126px; LEFT: -130px"  class="wbim_box_pop"></div>  </div>  </div>  <div style="POSITION: absolute; BOTTOM: 0px; RIGHT: 0px"  class="wbim_min_box_col2">  <div class="wbim_min_box">  <div class="wbim_min_friend">  <p class="statusbox">  <span class="wbim_status_offline"></span>  </p>  私信聊天 [ <span class="wbim_online_count" title="在线联系人">3</span> ]<span  style="DISPLAY: none; COLOR: gray; MARGIN-LEFT: 80px"  class="webim_rec_count"></span>  </div>  <div class="wbim_min_line wbim_min_linefor3"></div>  <div class="wbim_min_chat">  <span class="wbim_icon_msg"></span><span style="DISPLAY: inline"  class="wbim_min_text_pre">正与 </span><span class="wbim_min_nick"  suda-uatrack="key=tblog_webim_behavior&amp;value=click_unread_message">自由kirayu</span><span  class="line"></span><span class="wbim_min_text">聊天中</span>  </div>  </div>  </div>  </div>  ';
			$("body").append(a);
			this.regEvents();
			this.fetchList();
			this.chatList.empty();
			this.pull();
		}
	}

}
/*
$(document).ready(function() {


	IM.init(1100);

})
 
*/